﻿using System;
using System.Web;
using Ext.Net;
using System.Collections.Generic;
using System.Collections;
using Film.Repository;


namespace PhuongDoAn.Admin.Age.Handler
{
    /// <summary>
    /// Summary description for ListHandler
    /// </summary>
    public class ListHandler : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/json";
            string query = "";
            int start = 0;
            int limit = 25;
            int count = 0;

            if (!string.IsNullOrEmpty(context.Request["query"]))
            {
                query = context.Request["query"];
            }
            if (!string.IsNullOrEmpty(context.Request["start"]))
            {
                int.TryParse(context.Request["start"], out start);
            }

            if (!string.IsNullOrEmpty(context.Request["limit"]))
            {
                int.TryParse(context.Request["limit"], out limit);
            }
            List<tblAge> result = new List<tblAge>();
            tblAgeRepository countryRepository = new tblAgeRepository();
            result = countryRepository.Filter(query, start, limit, out count);


            List<tblAgeHandler> listHandler = result.ConvertAll<tblAgeHandler>(delegate(tblAge e)
            {
                return new tblAgeHandler() { AgeID = e.AgeID, AgeName = e.AgeName  };
            });
            context.Response.Write(string.Format("{{'Data':{0},'TotalRecords':{1}}}", JSON.Serialize(listHandler), count));

           
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }

    public class tblAgeHandler
    {
        public int AgeID { get; set; }
        public string AgeName { get; set; }
    }
}